package javaweb_work01.main.Dao;

import javaweb_work01.login.Utils.DruidUtils;
import javaweb_work01.main.Entity.Students;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * 访问数据库实现删除指定学号的学员信息
 */
public class DeleteStudentsDaoImp implements DeleteStudentsDao{
    @Override
    public int deleteStudents(int studentsId) {
        try {
            //使用连接池创建QueryRunner对象
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            //编写sql语句
            String sql1 = "delete from students where num = ?";
            //执行语句
            int delete = qr.update(sql1, studentsId);
            //返回结果
            return delete;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //删除失败返回0
        return 0;
    }
}
